package com.topscore.uke.mvp.model;

import com.topscore.uke.mvp.contractors.SaveMemberAddressContractor;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.network.request.SaveMemberAddressRequest;
import com.topscore.uke.network.retrofit.HandleErrorSubscriber;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 71468 on 2017/11/21.
 */

public class SaveMemberAddressModel implements SaveMemberAddressContractor, SaveMemberAddressContractor.Model {
    private CallBack callBack;

    public SaveMemberAddressModel(CallBack callBack) {
        this.callBack = callBack;
    }

    @Override
    public void save(SaveMemberAddressRequest request) {
        mService.saveMemberAddress(request)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse>(callBack) {
                    @Override
                    public void onSuccess(BaseResponse response) {
                        callBack.onSaveSuccess();
                    }
                });
    }

    @Override
    public void delete(String id) {
        mService.deleteMemberAddressItem(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse>(callBack) {
                    @Override
                    public void onSuccess(BaseResponse response) {
                        callBack.onDeleteSuccess();
                    }
                });
    }
}
